﻿@model List<Menu>
@(
 Layout = null
)
<div id="Menu_accordion">
    @if (ViewBag.menuId != null)
    {
        foreach (var item in Model.OrderBy(p => p.OrderIndex))
        {
        <div>
            <h3>
                <a href="#">
                    @Html.Encode(item.MenuText) </a>
            </h3>
            <div>
                <ul>
                    @foreach (var item1 in item.Children.Where(a => a.ParentID == item.ID && a.Enable == true).OrderBy(p => p.OrderIndex))
                    {
                        <li>
                            @Ajax.ActionLink(item1.MenuText, item1.Action == null ? "Index" : item1.Action, item1.Controller == null ? "Index" : item1.Controller, new { MenuId = item1.ID, area = item1.Area == null ? "" : item1.Area }, new CustomAjaxOptions(), null)</li>
                    }
                </ul>
            </div>
        </div>
        }
    }
</div>
<script type="text/javascript">
    $(function () {
        if ($.trim($("#Menu_accordion").html()) == "") {
            myLayout.close("west");
        }
        else {
            myLayout.open("west");
            $("#Menu_accordion").accordion({
                icons: { 'header': 'menu-close', 'headerSelected': 'menu-open' },
                collapsible: false,
                header: "> div > h3",
                fillSpace: false,
                autoHeight: false
            });
        }
        $("#Menu_accordion div div ul li a").click(function () {
            $("#Menu_accordion div div ul li a").removeClass("aclick");
            $(this).addClass("aclick");
        });


    })

</script>
@{
    if (ViewBag.menuId != null)
    {
    <script type="text/javascript">
        $(function () {
            $.get("@Url.Action("ChannelDashboard", "User", new { menuId = ViewBag.menuId })", function (data) {
                $("#main").html(data);
            });
        })
    </script>
    }
}
